Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-09-08, 08:32 PM
Junior Member
 
Join Date: Sep 2004
Posts: 2
the12php
Default

I'm trying to insert data in a table I named "INFO" from web browser
using Html,PHP, to Domain server supporting MYsqlAdmin.

I am able to connect succefully
The problem is inserting Data (using php)
from variables I already assigned.
$First, $Last, and $Email



I used this to connect:

mysql_connect ("$Cerver, "$User", "$Pw") or
die ("couldn't Connect")

Now I want to insert into table "INFO" "First, Last, Email"
the values $First, $Last, $Email.





I tried this:

INSERT INTO `INFO` (`First` , `Last` , `Email`)

VALUES ( '$First' , '$Last' , '$Email');

And got this:

Parse error: parse error, unexpected T_STRING in (the line where my Insert INFO starts)

Did I miss something?

Thanks!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-09-08, 09:34 PM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

Hope you haven't forgot to use mysql_query() to run your query :P

Btw, you don't need to put the '´' in the table's name and/or fields.
And... don't forget that tables and fields' names are case sensitive.

Try using this:
Code:
<?php

mysql_query("INSERT INTO INFO (First , Last , Email) VALUES ( '" . $First . "' , '" . $Last . "' , '" . $Email . "')");

// Or....

mysql_query("INSERT INTO INFO VALUES ( '" . $First . "' , '" . $Last . "' , '" . $Email . "')");

?>
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
  #3 (permalink)  
Old 2004-09-10, 06:58 PM
Guest
Guest
 
Posts: n/a
Default

Thanks gesf

the error is gone now.

The script takes form fields entered, turns them into php variables and inserts those variables into INFO.
It connects and doesn't display any inserting errors.

The problem

When i log on mysqladmin and browse the INFO database, it shows as nothing being inserted.

The variables do have data on them through $_GET because I echoed them out before I inserted them so i'm pretty sure its not a blank data or "null" issue.



What else have i missed? :huh:

Any closing-query command
or database select needed before inserting into a database?

thanks again
Reply With Quote
  #4 (permalink)  
Old 2004-09-11, 06:35 PM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

I see! Use the $_GET and/or $_POST superglobal arrays.

Use $_GET to retrieve the data from the URL, or if it was sent through form with GET method.

Use $_POST to retrieve data sent through form with POST method.

Example:
Code:
<?php

mysql_query("INSERT INTO INFO VALUES ( '" . $_POST['First'] . "' , '" . $_POST['Last'] . "' , '" . $_POST['Email'] . "')");

?>
Cheers
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
  #5 (permalink)  
Old 2004-09-15, 04:44 PM
Guest
Guest
 
Posts: n/a
Default

What I want to do
Web form simulation
-----------------------------------------------------------

Enter Your

Last Name: [ ]
First Name:[ ]
Email: [ ]

Then
click

[submit"]

----------------------------------------------------------------------------------





I created a basic web form (HTML) that will ask you to Input your Last Name, First Name and Email address.
as shown above.

Once it recieves the input

I ask it to get the Values inserted by user using $_GET

I assign each of the 3 input fields to 3 different variables.

$Last
$First
$Email


I want to connect to mysqladmin server (webhost) and insert (update) a Table I created called INFO





This is my code

Code:
<?

// Variables = Info collected on HTML webform through GET


$First= $_GET['First'];
$Last= $_GET['Last'];
$Email= $_GET['Email'];



// The Server (Mysqladmin web host godaddy.com ), The User and Pass

$Host= "Host.com";
$User= "Username";
$Pass= "Password";


// Connect to database or  "couldn't connect" will be display

    mysql_connect("$Host", "$User","$Pass" ) 
           or
      die ("Couldn't connect ");
   

// inserting data into a table called "INFO"

mysql_query("INSERT INTO INFO (First , Last , Email) VALUES ( '" . $First . "' , '" . $Last . "' , '" . $Email . "')");	
	
	
mysql_close();	
	

	


?>

Everything works , It recieves, It connects without errors (thanks to your help)

but when i log on to mysqladmin and check if the table "INFO" has any input, it shows as no records.
:blink:
Reply With Quote
  #6 (permalink)  
Old 2004-09-16, 06:18 AM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

Hunn, not sure!
Try to use this:
Code:
mysql_query("INSERT INTO INFO (First , Last , Email) VALUES ( '$First' , '$Last' , '$Email')");
Instead of this:
Code:
mysql_query("INSERT INTO INFO (First , Last , Email) VALUES ( '" . $First . "' , '" . $Last . "' , '" . $Email . "')");
In last case try to change the for method to post, as well as the variables:
Code:
$First= $_GET['First'];
$Last= $_GET['Last'];
$Email= $_GET['Email'];
Cheers
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
  #7 (permalink)  
Old 2004-09-25, 03:26 PM
Congo
Guest
 
Posts: n/a
Default

This is maybe true, but i don`t see mysql_select_db anywhere, some thing like this :
Code:
$mysql = mysql_select_db($database_dbi, $dbi);
if (!$mysql) {
echo "Cannot select database";
}
$query = "select count(*) from users where 
passwd=md5($passwdc);
$result = mysql_query($query);
if(!$result) {
echo "Cannot run query";
}
where :
Code:
$dbi = mysql_connect($hostname_dbi, $username_dbi, $password_dbi) or die(mysql_error());
$database_dbi = "your db";
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:42 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.