Jump to content

Problem with insert query


floridaflatlander

Recommended Posts

I have worked on this for hours and can't find the problem.

 

My $r doesn't query for some reason

I've tested the database connection and variables with echo statements and they work, also there is an SELECT statement above this that checks to see if the name is in use and it works like it is suppose to. I just can't get this code to work.

I have php5, the database connection with host, user, pw and database name are correct and isn't redefined or exited. The SELECT I mentioned uses the same connection.

 

Can any one see whats wrong with this

 

$q = "INSERT INTO vendors (id_vendor, name, s_discrip, discript, phone, zip, id_loca, email, web_title, web_url, photo, date_reg)

VALUES (NULL, '$name', '$s_discrip', '$discrip', '$phone', '$zip', '$loca', '$email', '$ws_title', '$ws_url', 'photo', CURRENT_TIMESTAMP);";

 

$r = mysqli_query($dbc, $q);

 

Thanks

S

Link to comment
https://forums.phpfreaks.com/topic/231034-problem-with-insert-query/
Share on other sites

I use mysqli_connect_error() ,  all tables are in the same database as the location table that fills out a drop down menu to get $loca and that works so I have a db connection.

 

I only have two integer columns. One is auto_increment and the other is a number representing the location

The mysqli_connect_error() comes in in an include statement before the queries, DB_HOST etc. are defined with define statments.

 

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL;'. mysqli_connect_error());

 

if (!$dbc){

trigger_error('Could not connect to Mysql: ' . mysqli_connect_error());

}

 

Also would think all is OK since I use two selects on the form that enters the info, one to check for user name the other to get location IDs

Oh, not mysqli_connect_error(), mysqli_error(). The latter is used to report errors in query executions.

if( !$result = mysqli_query($dbc, $query) ) {
     echo "<br>Query string: $query<br>Resulted in error: " . mysqli_error($dbc) . '<br>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.