Jump to content

A Little Newbie Help Using PHP To Load Form Post to MySQL Please


captdavid

Recommended Posts

Have simple Mysql db containing one table (catalog) with 6 fields.... First field (id_num) is auto increment and primary.

 

This script connects and dislplays fields as requested:

 

?php

include 'config.php';
include 'opendb.php';

$data = mysql_query("SELECT * FROM catalog")
    or die(mysql_error());
    Print "<table border=0 cellpadding=3>";
    while($info = mysql_fetch_array( $data ))
    {
    Print "<tr>";
    Print " <td align=center>".$info['mfg']."<br><img src=".$info['photo_path'] . " width=150 height=100><br>"   .$info['model'] .  "</td> ";
    
    Print "</tr>";
   
    Print "</table>";
     }
   


?>

 

Attempting to populate table using following form as input:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>


<body>
<table border=0 >
<form method="post"  action="../php-bin/catalog_upload.php">
<input type="hidden" name="id_num" value="NULL">
<tr><td>
Type<br>
<select name="type" size="1">
<option value="Road Bike">Road Bike</option>
<option value="Cruiser">Cruiser</option>
<option value="BMX">BMX</option>
<option value="Mountain Bike">Mountain Bike</option>
<option value="Other Bike">Other Bike</option>
</select>
</td></tr>
<tr><td>
Manufacturer<br>
<select name="mfg" size="1">
<option value="Schwinn">Schwinn</option>
<option value="Mongoose">Mongoose</option>
<option value="Sun">Sun</option>
<option value="GT">GT</option>
<option value="Firmstrong">Firmstrong</option>
</select>
</td></tr>
<tr><td>
Model<br>
<textarea name="model" rows="0" cols="50"></textarea>
</td></tr>
<tr><td>
Description<br>
<textarea name="desc" rows="10" cols="50"></textarea>
</td></tr>
<tr><td>
Photo Path<br>
<textarea name="photo_path" rows="0" cols="100"></textarea>
</td></tr>
<tr><td>
<input type="submit">
&nbsp &nbsp
<input type="reset">
</td></tr>
</form>
</table>
</body>
</html>

 

catalog_upload.php as follows:

 

<?
include 'config.php';

$id_num=$_POST['id_num'];
$type=$_POST['type'];
$mfg=$_POST['mfg'];
$model=$_POST['model'];
$desc=$_POST['desc'];
$photo_path=$_POST['photo_path'];

include 'opendb.php';

$query = ("insert into 'catalog' (`id_num`, `mfg`, `type`, `model`, `desc`, `photo_path`) values ('$id_num', '$type', '$mfg', '$model', '$desc', '$photo_path')");
mysql_query($query);



?>

 

Script returns no errors on execution of submit... PhpMyadmin shows no rows added to table (catalog) after execution of script..

 

Any Suggestions appreciated

TIA

Link to comment
Share on other sites

catalog_upload.php:

<?php
include 'config.php';

$id_num=$_POST['id_num'];
$type=$_POST['type'];
$mfg=$_POST['mfg'];
$model=$_POST['model'];
$desc=$_POST['desc'];
$photo_path=$_POST['photo_path'];

include 'opendb.php';

$query = ("INSERT INTO catalog (id_num, mfg, type, model, desc, photo_path) values ('', '$type', '$mfg', '$model', '$desc', '$photo_path')");
mysql_query($query) or die("<pre>MySQL Error:\nMySQL Returned: ".mysql_error()."\nQuery: ".$query);



?>

EDITED SOURCE

Link to comment
Share on other sites

Okay, 1 other thing I seen, you have the action="../php-bin/catalog_upload.php" in the form element in the HTML form

 

change that to an absolute path http://yoursite/php-bin/catalog_upload.php

 

Also add something to the end of the catalog_upload.php like:

 

echo("<b>The Form Was Submitted</b>"); to get some kind of verification that you hit the page

Link to comment
Share on other sites

Ok, at least the absolute path got a Mysql error;

 

MySQL Error:

MySQL Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, photo_path) values ('NULL', 'BMX', 'Mongoose', '2008 Brawler', 'BMX Plus!,' at line 1

Query: INSERT INTO catalog (id_num, mfg, type, model, desc, photo_path) values ('NULL', 'BMX', 'Mongoose', '2008 Brawler', 'BMX Plus!, Jan 2008 - The Brawler rocks chromoly tubing, Alex rims, Kenda tires, a solid set of three-piece cranks and is topped off nicely with a pair of Primo grips.', 'http://www.mongoose.com/bmx/MongooseFiles/ProductImages/2590_1_large.jpg')

 

Are Characters in the "desc" possibly causing errors?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.